package com.ruoyi.web.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.otc.domain.Topic;
import com.ruoyi.otc.domain.User;
import com.ruoyi.otc.service.ITopicService;
import com.ruoyi.web.api.base.ApiBaseController;
import com.ruoyi.web.api.vo.TopicVo;
import com.ruoyi.web.constant.ApiConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author gjp
 */
@Api(value = "评测管理接口",tags = "评测管理接口")
@RestController
@RequestMapping(ApiConstant.API_V1+"topic")
public class ApiTopicController extends ApiBaseController {

    @Autowired
    private ITopicService topicService;

    /**
     * 新增保存评测
     */

    @ApiOperation("添加评测")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody TopicVo topicVo)
    {
        Topic topic = new Topic();
        BeanUtils.copyProperties(topicVo,topic);
        topic.setCreateTime(new Date());
        topic.setUpdateTime(new Date());
        topic.setDel(false);
        return toAjax(topicService.insertTopic(topic));
    }
    @ApiOperation("修改评测")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody TopicVo topicVo)
    {
        Topic topic = topicService.getById(topicVo.getId());
        BeanUtils.copyProperties(topicVo,topic);
        topic.setUpdateTime(new Date());
        return toAjax(topicService.updateById(topic));
    }

    @ApiOperation("删除评测")
    @PostMapping("/delete/{id}")
    @ResponseBody
    public AjaxResult delete(@PathVariable("id") Long id)
    {
        Topic topic = topicService.getById(id);
        topic.setUpdateTime(new Date());
        topic.setDel(true);
        return toAjax(topicService.updateById(topic));
    }
    @ApiOperation("详情")
    @PostMapping("/info/{id}")
    @ResponseBody
    public AjaxResult info(@PathVariable("id") Long id)
    {
        Topic topic = topicService.getById(id);
        return AjaxResult.success(topic);
    }
    @ApiOperation("查询评测列表")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody TopicVo topicVo)
    {
        startPage();
        QueryWrapper<Topic> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(topicVo.getName()),"name",topicVo.getName()).eq("del",false);
        List<Topic> list = topicService.list(wrapper);
        return getDataTable(list);
    }


    @ApiOperation("前台-企业画像管理-评测问卷")
    @PostMapping("/allList")
    @ResponseBody
    public AjaxResult allList()
    {
        QueryWrapper<Topic> wrapper = new QueryWrapper<>();
        wrapper.eq("del",false);
        List<Topic> list = topicService.list(wrapper);
        return AjaxResult.success(list);
    }


}
